package com.zs.common.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 服务线程变量
 */
@Slf4j
public class ServiceContext {

    private static final ThreadLocal<ConcurrentHashMap<String, String>> THREAD_LOCAL = new ThreadLocal<>();

    private ServiceContext() {
    }


    private static Map<String, String> get() {
        ConcurrentHashMap<String, String> map = THREAD_LOCAL.get();
        if (map == null) {
            map = new ConcurrentHashMap<>();
            THREAD_LOCAL.set(map);
        }
        return map;
    }

    private static final String SN = "sn";

    public static void setSN(String sn) {
        log.debug(" setting sn to " + sn);
        get().put(SN, sn);
    }

    public static String getSN() {
        return get().get(SN);
    }

    public static void clear() {
        THREAD_LOCAL.remove();
    }


}